package com.tianwen.management.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: yygh_parent
 * @description
 * @author: tianwen
 * @create: 2023-02-15 21:09
 **/
@Data
public class Result {
    private Boolean success;
    private Integer code;
    private String message;
    private Map<String,Object> data=new HashMap<>();
    Result(){}
    public static Result ok(){
        Result result=new Result();
        result.setCode(REnum.SUCCESS.getCode());
        result.setSuccess(true);
        result.setMessage("成功");
        return result;
    }
    public static Result error(){
        Result result=new Result();
        result.setCode(REnum.ERROR.getCode());
        result.setSuccess(false);
        result.setMessage("失败");
        return result;
    }
    public Result success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public Result message(String message){
        this.setMessage(message);
        return this;
    }
    public Result code(Integer code){
        this.setCode(code);
        return this;
    }
    public Result data(String key,Object value){
        this.data.put(key, value);
        return this;
    }
    public Result data(Map<String,Object> map){
        this.setData(map);
        return this;
    }
}
